package me.softwareengineer.guice.rendering.domain;

import java.util.List;
import java.util.Map;

import me.softwareengineer.guice.rendering.listener.EndListEvent;
import me.softwareengineer.guice.rendering.listener.Listener;
import me.softwareengineer.guice.rendering.listener.StartListEvent;

/**
 * Represents an association list. An association list contains groups of "terms and definitions,
 * metadata topics and values, questions and answers, or any other groups of name-value data"
 * 
 * <p>
 * Event: the following event is generated during {@link #render(Listener)}:
 * <ul>
 * <li>{@link StartListEvent} with ListType.DEFINITION</li>
 * <li>{@link EndListEvent} with ListType.DEFINITION</li>
 * </ul>
 * </p>
 * 
 * <pre>
 * This class is thread-safe and can be cached/re-used and used concurrently.
 * </pre>
 * 
 * @author yadtahir
 * @since 1.0
 */

//This class is marked as final as we want to make it immutable as much as possible
public final class DefinitionListElement extends Element implements
		ListElement {

	/**
	 * Creates a definition list element with no properties.
	 * 
	 * @param children
	 *            the children of the list
	 */
	public DefinitionListElement(List<Element> children) {
		super(children);
	}

	/**
	 * Creates a definition list element with the provided properties
	 * 
	 * @param children
	 *            the children of the list
	 * @param properties
	 *            the properties of the element. For more info, see
	 *            {@link HasProperties}
	 */
	public DefinitionListElement(List<Element> children,
			Map<String, String> properties) {
		super(children, properties);
	}

	/**
	 * {@inheritDoc}
	 * <p>
	 * This method triggers the following event:
	 * <ul>
	 * 	<li>{@link EndListEvent} with ListType.DEFINITION</li>
	 * </ul> 
	 * </p>
	 * 
	 * @see EndListEvent
	 *
	 */
	@Override
	public void afterElement(Listener listener) {
		EndListEvent e = new EndListEvent(ListType.DEFINITION, getAllProperties());
		listener.onEvent(e);
	}

	/**
	 * {@inheritDoc}
	 * <p>
	 * This method triggers the following event:
	 * <ul>
	 * 	<li>{@link StartListEvent} with ListType.DEFINITION</li>
	 * </ul> 
	 * </p>
	 * 
	 * @see StartListEvent
	 *
	 */
	@Override
	public void beforeElement(Listener listener) {
		StartListEvent e = new StartListEvent(ListType.DEFINITION, getAllProperties());
		listener.onEvent(e);
	}

}
